
var articleType={
    sortArticle:"sortArticle",
    cloudTag: "cloudTag",
    homeInfo: "homeInfo"
}

$(function () {
    //添加文章分类
    articleSort();
    //添加标签
    tagCloud();
    //修改头像信息
    changeHeader();
    //设置文章为空
    $("#commentContentInput").val("");

    var  queryString = getQueryString("model");
    if(queryString === 'articleInfo'){
        var  id = getQueryString("id");
        showArticleContent(id);
        replayCount(id);
    }else if(queryString === 'cloudTag'){
        //标签
        var  page = getQueryString("page");
        var  tagId = getQueryString("tagId");
        tagArticleList(page, tagId);
    }else if(queryString === 'sortArticle'){
        //标签
        var  page = getQueryString("page");
        var  sortId = getQueryString("sortId");
        sortArticleList(page, sortId);
    }else if(queryString === 'search'){
        //标签
        var  page = getQueryString("page");
        var  searchValue = getQueryString("searchValue");
        homeContentList(page, searchValue);
    }else if(queryString === 'register'){
        //添加注册页
        $(".index-content").load("/static/register.html");
    }else if(queryString === 'login'){
        //添加登录页
        $(".index-content").load("/static/login.html");
    } else if(queryString === 'forget'){
        //添加忘记密码页
        $(".index-content").load("/static/forget-user.html");
    } else if(queryString === 'me'){
        showMeContent();
    }else {
        //添加内容
        homeContentList(1, null);
    }

    //设置a标签的地址
    // var href = $(".tiaozhuan").attr("href");
    // console.info(href);
    // $(".tiaozhuan").attr("href", content_url+href);
    toMyUrl();

});

function toMyUrl() {
    var x = $('.tiaozhuan');
    for (var i = x.length - 1; i >= 0; i--) {
        var href = $(x[i]).attr("href");
        $(x[i]).attr("href", content_url+href)
    }

}

function replayCount(articleId){
    $("#comment").click(function(){
        var replyName = getLocalStorage('malongxiaozhan-user-userName', expUser);
        var content = $("#content").val();
        if(replyName===null || replyName==='undefined'){
            alert("未登录");
            return false;
        }
        if(content===null || content===''){
            alert("评论内容为空");
            return false;
        }


        var obj = new Object();
        obj.commentContent=content;
        obj.articleId=articleId;
        //$(".comment-list").addCommentList({data:[],add:obj});
        comReplay(obj, articleId);
    });
}

function comReplay(obj, articleId){
    var osName = getOs();
    var address = getAddress();
    var browse = getBrowse();
    obj.commentAddress=address;
    obj.commentSystem=osName;
    obj.commentBrowser=browse;
    if(obj.commentContent===null|| obj.commentContent.length>50){
        alert("评论内容最多50个字符");
        return false;
    }

    var cookieJWT = getLocalStorage('malongxiaozhan-user-jwt', expUser);
    $.ajax({
        type: 'POST',
        url: '/blog/blogOperate/blogComment', //要请求的url地址
        data: JSON.stringify(obj), //传入的数据 转换为json对象
        dataType: "json",
        headers: {
            "Content-Type": 'application/json',
            "token": cookieJWT
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                showComment(articleId);
                $("#content").val('');
            }
        }
    });
}

function getBrowse(){
    var browse = "";
    const userAgent = navigator.userAgent;
    if (userAgent.indexOf("Chrome") > -1) {
        browse = "Chrome";
    } else if (userAgent.indexOf("Firefox") > -1) {
        browse = "Firefox";
    } else if (userAgent.indexOf("Safari") > -1) {
        browse = "Safari";
    } else if (userAgent.indexOf("Edg") > -1) {
        browse = "Edge";
    } else if (userAgent.indexOf("MSIE") > -1) {
        browse = "IE";
    }
    return browse;
}

function getIp(){
    var ip = "127.0.0.1";
    $.ajax({
        url: 'https://api.ipify.org?format=json',
        type: 'GET',
        dataType: 'json',
        async: false,
        success: function(data) {
            ip = data.ip;
            // 这里可以根据需要进行其他操作，比如将IP地址显示在页面上等
        }
    });

    return ip;
}

function getAddress(){
    var address = null;
    var ip = getIp();
    $.ajax({
        type: 'GET',
        url: '/blog/blogViewController/getUserIp?ip='+ip,
        dataType: "json",
        async: false,
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function(data) {
            if(data.code === "200" && data.data !=='' && data.data !=null) { // 如果获取地址信息成功
                address = data.data.location;
            }
            else { // 如果获取地址信息失败
                console.log('获取IP地址对应的物理地址失败：' + data.msg);
            }
        },
        error: function(xhr, textStatus) {
            console.log('获取IP地址对应的物理地址失败：' + textStatus);
        }
    });
    if(address === '' || address == null){
        address = "中国";
    }

    return address;
}


function getOs(){
    var OSName="Unknown OS";
    if (navigator.userAgent.indexOf("Win")!=-1) OSName="Windows";
    if (navigator.userAgent.indexOf("Mac")!=-1) OSName="MacOS";
    if (navigator.userAgent.indexOf("X11")!=-1) OSName="UNIX";
    if (navigator.userAgent.indexOf("Linux")!=-1) OSName="Linux";
    console.log('当前操作系统类型：' + OSName);
    return OSName;
}

//修改头像
function changeHeader(){

    $.ajax({
        type: 'GET',
        url: '/blog/blogArticleView/getMeContentInfoView',
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                $(".meHeaderImg").attr("src", result.data.showHeaderImg);
            }

        }
    });

}



function homeContentList(page, searchValue){
    var searchValues ;
    if(searchValue!==null && searchValue!=="null"){
        searchValues = decodeURIComponent(decodeURIComponent(searchValue));
    }
    var param = {"pageNo":page,"pageSize":10, "articleTitle":searchValues};
    $.ajax({
        type: 'POST',
        url: '/blog/blogArticleView/homeContent',
        data: JSON.stringify(param),
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var homeContenJsonData = {
                    "pageTotal": result.data.total,
                    "pageCurrent": result.data.current,
                    "data": result.data.records,
                    "pages": result.data.pages,
                };
                //去除内容
                $(".home-content").empty();
                $(".home-content-page").empty();
                //添加内容
                var commonHomes = commonHome(homeContenJsonData);
                $(".home-content").html(commonHomes.html);
                //添加内容分页
                $(".home-content-page").html(homePage(homeContenJsonData, articleType.homeInfo, 1));
                homeImgWh(commonHomes.imgId);
            }

        }
    });
}

function homeImgWh(imgId){

    //设置图片等比宽高 220*120
    if(imgId!==null && imgId.length>0){
        for(var i=0; i<imgId.length; i++){
            var ids = "#img_"+imgId[i];
            var idhW = "#imgdivW_"+imgId[i];
            var idhH = "#imgdivH_"+imgId[i];
            var widths = $(idhW).width();
            var heights = $(idhH).height();

            var dataImg = $(ids).attr("data").split(",");
            var width =  dataImg[0];
            var height = dataImg[1];
            if(width>widths){
                height = widths/width*height;
                width = widths;
            }
            if(height>heights){
                width = heights/height*width;
                height = heights;
            }

            $(ids).width(width);
            $(ids).height(height);
        }

    }
}

/**显示关于我内容*/
function showMeContent(){
    //去除内容
    $(".home-content").empty();
    $(".home-content-page").empty();
    //添加文章
    meInfoContent();
}

/**显示文章具体内容*/
function showArticleContent(id){
    //去除内容
    $(".home-content").empty();
    $(".home-content-page").empty();
    //添加文章
    articleContent(id);
}

/**显示文章分类*/
function sortArticleList(page, sortId){
    //去除内容
    $(".home-content").empty();
    $(".home-content-page").empty();
    //添加内容
    sortHomeContent(page,sortId, articleType.sortArticle);
}

/**显示标签分类*/
function tagArticleList(page,tagId){
    //去除内容
    $(".home-content").empty();
    $(".home-content-page").empty();
    //添加内容
    tagHomeContent(page, tagId, articleType.cloudTag);
}

/**上一页下一页内容*/
function toContentPage(page, model, id){
    $('body,html').animate({
        scrollTop: 0
    },0);
    //标签
    if(model === articleType.cloudTag){
        //tagArticleList(page, id);
        window.location = "/index.html?model=cloudTag&page="+page+"&tagId='"+id;
    }

    if(model === articleType.sortArticle){
        // sortArticleList(page,id)
        window.location = "/index.html?model=sortArticle&page="+page+"&tagId='"+id;
    }

    if(model === articleType.homeInfo){
        //homeContentList(page, null)
        window.location = "/index.html?model=search&page="+page;
    }

}



function commonHome(homeContenJson) {
    var html = "";
    var imgId = [];
    for (var i = 0; i < homeContenJson.data.length; i++) {
        var datVal = homeContenJson.data[i];
        html += '<div class="summary-list mb-2 col-12 col-sm-12 tcol-md-12 tcol-lg-12  col-xl-12 col-xxl-12 bg-light" >\n' +
            '                    <div class="row p-0 m-0 dlcoverContent  ">\n' +
            '                        <div class="col-3  col-sm-3 tcol-md-3 tcol-lg-3  col-xl-3 col-xxl-3  align-self-center " id="imgdivW_'+datVal.articleHref+'">\n' +
            '                          <div class=" w-100  h-75 " style="text-align: center" >\n' +
            //文章内容
            '                                <a href="'+content_url+'/index.html?model=articleInfo&id='+datVal.articleHref+'" target="" style="text-align: center">' +
            '                                    <img class=" " src=' + datVal.img + ' alt="' + datVal.imgAlt + '" data="'+datVal.imgWidth+','+datVal.imgHeight+'" id="img_'+datVal.articleHref+'" style="height: 100px;"/>\n' +
            '                                </a>\n' +
            '                            </div>\n' +
            '                        </div>\n' +
            '                        <div class="col-9  col-sm-9 tcol-md-9 tcol-lg-9  col-xl-9 col-xxl-9  mt-2" id="imgdivH_'+datVal.articleHref+'"> \n' +
            '                            <div class="text-muted mb-2 f-12">\n' +
            //文章分类
            '                                <a href="javascript:void(0);" title="查看当前标签下更多文章" onclick="sortArticleList(1,'+datVal.articleSortId+');">\n' +
            '                                    <img class="avatar" src="' + datVal.sortImg + '" alt="' + datVal.sortAlt + '">\n' +
            '                                    <span >' + datVal.sortAlt + '</span>\n' +
            '                                </a>\n' +
            '                                <span><i class="fa fa-calendar-times-o ms-2 "></i>' + datVal.articleTime + '</span>\n' +
            '                            </div>\n' +
            '                            <h2 class="mt-0 fw-bold text-success f-17">\n' +
            //文章内容
            '                                <a href="'+content_url+'/index.html?model=articleInfo&id='+datVal.articleHref+'" target=""  >' + datVal.articleTitle + '</a>\n' +
            '                            </h2>\n' +
            '                            <p class="d-none d-sm-block mb-2 f-15" style="word-wrap: break-word; tword-break: break-all;white-space: normal;">' + datVal.articlePreface + '</p>\n' +
            '                            <div class="text-muted mb-0 f-12">\n' +
            //文章标签
            '                                <a href="'+content_url+'/index.html?model=cloudTag&page=1&tagId='+datVal.cloudTagId+'" title="查看当前标签下更多文章" ">\n' +
            '                                    <i class="fa fa-book ms-1"></i>' + datVal.cloudValue + '</a>\n' +
            '                                <span><i class="fa fa-eye ms-2"></i>' + datVal.articleEye + '</span>\n' +
            '                            </div>\n' +
            '                        </div>\n' +
            '                    </div>\n' +
            '                </div>';

        imgId.push(datVal.articleHref);

        }
    var result = {"html":html, "imgId":imgId};
    return result;
}

function homePage(homeContenJson,model,id) {

    var htmlPage = "<div class=\"col-12 col-sm-12\tcol-md-12\tcol-lg-12  col-xl-12 col-xxl-12 mt-3\">\n" +
        "                    <div class=\"text-center mt-2 mt-sm-1 mt-md-0 mb-3 f-16\">";
    if (homeContenJson.pageCurrent === 1) {
        htmlPage += '<span class="text-secondary" title="当前页已经是首页">上一页</span>';
    }
    if (homeContenJson.pageCurrent !== 1) {
        htmlPage += '<a class="text-success" href="javascript:void(0);" onclick="toContentPage(' + (homeContenJson.pageCurrent - 1) +',\''+ model +'\','+ id +')">上一页</a>';
    }
    htmlPage += '<span className="mx-2">&nbsp;第&nbsp;' + homeContenJson.pageCurrent + '/' + homeContenJson.pages + '&nbsp;页&nbsp;</span>'
    if (homeContenJson.pageCurrent === homeContenJson.pages || homeContenJson.pageCurrent > homeContenJson.pages) {
        htmlPage += '<span class="text-secondary" title="当前页已经是最后一页">下一页</span>';
    }
    if (homeContenJson.pageCurrent !== homeContenJson.pages && homeContenJson.pageCurrent < homeContenJson.pages) {
        htmlPage += '<a class="text-success" href="javascript:void(0);" onclick="toContentPage(' + (homeContenJson.pageCurrent + 1) +',\''+ model +'\','+ id +')">下一页</a>';
    }
    htmlPage += ' </div>\n' +
        '                </div>';


    return htmlPage;
}

function articleSort() {
    $.ajax({
        type: 'GET',
        url: '/blog/blogArticleView/getSortList',
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var htmlArticleSort = '';
                for (var i = 0; i < result.data.length; i++) {
                    var sortValue = result.data[i];
                    htmlArticleSort += '<li class="list-group-item d-flex justify-content-between align-items-center  py-2 bg-light">\n' +
                        '                        <a class="category-item" href="'+content_url+'/index.html?model=sortArticle&page=1&sortId='+sortValue.href +'"  title="' + sortValue.content + '">' + sortValue.title + '</a>\n' +
                        '                        <span class="badge text-center" title="当前分类下有' + sortValue.contentNu + '">1</span>\n' +
                        '                    </li>';
                }

                $(".article-sort").html(htmlArticleSort);
            }

        }
    });

}

function tagCloud() {
    $.ajax({
        type: 'GET',
        url: '/blog/blogArticleView/getTagList',
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var htmlTagCloud = '';
                for (var i = 0; i < result.data.length; i++) {
                    var tagValue = result.data[i];
                    htmlTagCloud += ' <a href="'+content_url+'/index.html?model=cloudTag&page=1&tagId='+tagValue.href+'" class="tags f-16" id="tag-' + i + '" title="【' + tagValue.content + '】标签下有' + tagValue.contentNu + '篇文章">' + tagValue.title + '</a>';
                }

                $(".my-tag").html(htmlTagCloud);
            }

        }
    });
}

//关于我
function meInfoContent() {

    $.ajax({
        type: 'GET',
        url: '/blog/blogArticleView/getMeContentInfoView',
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var blogMeInfo = result.data;
                let blogMeInfoHtml = '    <div class=" col-12 px-3 mb-2 mb-md-3 bg-light  container  ">\n' +
                    '        <div class="card rounded-0 border-0 bg-light" id="article">\n' +
                                //文章头信息
                    '            <div class="card-body px-2 px-md-3 pb-0">\n' +
                    '                <h1 class="card-title text-left font-weight-bold text-info">关于我</h1>\n' +
                    '                <hr>\n' +
                    '                <div class="article-body " id="blogMeContent" ></div>\n' +
                    '            </div>\n' +
                    '        </div>\n' +
                    '    </div>';
                $(".home-content").html(blogMeInfoHtml);
                $("#blogMeContent").addClass("markdown-body editormd-html-preview").append(blogMeInfo.aboutMeHtml);

            }

        }
    });


}

//文章内容
function articleContent(id) {

    $.ajax({
        type: 'GET',
        url: '/blog/blogArticleView/getContentInfo',
        data: 'id='+id,
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var articleContentJson = result.data;
                let articleContentHtml = '<div class=" col-12 px-3 mb-2 mb-md-3 bg-light h-auto  container  ">\n' +
                    '        <ul class="breadcrumb bg-light p-0 m-0 border-0 rounded-0  f-15 ">\n' +
                    '            <li class="breadcrumb-item">\n' +
                    '                <i class="fa fa-home mr-1"></i><a class="ms-2" href="'+content_url+'/">首页</a>\n' +
                    '            </li>\n' +
                    '            <li class="breadcrumb-item">\n' +
                    '                <a href="'+content_url+'/index.html?model=sortArticle&page=1&sortId='+articleContentJson.articleSortHrf +'" >' + articleContentJson.articleSort + '</a>\n' +
                    '            </li>\n' +
                    '            <li class="breadcrumb-item active d-none d-md-block" aria-current="page">' + articleContentJson.articleTitle + '</li>\n' +
                    '            <li class="breadcrumb-item active d-md-none" aria-current="page">当前位置</li>\n' +
                    '        </ul>\n' +
                    '    </div>\n' +
                    '    <div class=" col-12 px-3 mb-2 mb-md-3  container  ">\n' +
                    '        <div class="card rounded-0 border-0 " id="article">\n' +
                    //文章头信息
                    '            <div class="card-body px-2 px-md-3 pb-0">\n' +
                    '                <h1 class="card-title text-center font-weight-bold text-info">' + articleContentJson.articleTitle + '</h1>\n' +
                    '                <hr>\n' +
                    '                <div class="text-center f-13">\n' +
                    '                    <span class="mx-2" data-toggle="tooltip" data-placement="bottom" title=""\n' +
                    '                          data-original-title="最后编辑于' + articleContentJson.updateTime + '">' + articleContentJson.createTime + '</span>\n' +
                    '                    <span class="mx-2">阅读&nbsp;' + articleContentJson.articleEye + '</span>\n' +
                    '                </div>\n' +
                    //文章信息
                    '                <div class="article-body mt-4 f-17 articleContent" style="line-height:1.8" ></div>\n' +
                    '                <div class="tag-cloud my-4">';
                //标签
                for (let i = 0; i < articleContentJson.articleCloudTag.length; i++) {
                    var articleCloudTagElement = articleContentJson.articleCloudTag[i];
                    articleContentHtml += '<a class="tags f-16" href="'+content_url+'/index.html?model=cloudTag&page=1&tagId='+articleCloudTagElement.href+'"  >' + articleCloudTagElement.content + '</a>';
                }
                articleContentHtml += '</div>' +
                    '<nav class="more-page f-16">\n' +
                    '                    <ul class="pagination justify-content-between">\n' +
                    '                        <li class="">\n' +
                    '                            <a class="d-none d-md-block" href="'+content_url+'/index.html?model=articleInfo&id='+articleContentJson.articlePageUp.articleUpHrf+'"   \n' +
                    '                               title="上一篇：' + articleContentJson.articlePageUp.articleUpTitle + '" >\n' +
                    '                                <i class="fa fa-chevron-left mr-1"></i>' + articleContentJson.articlePageUp.articleUpTitle + '</a>\n' +
                    '                            <a class="d-md-none" href="'+content_url+'/index.html?model=articleInfo&id=' + articleContentJson.articlePageUp.articleUpHrf + '">\n' +
                    '                                <i class="fa fa-chevron-left mr-1"></i>上一篇</a>\n' +
                    '                        </li>\n' +
                    '                        <li class="">\n' +
                    '                            <a class="d-none d-md-block" href="'+content_url+'/index.html?model=articleInfo&id='+articleContentJson.articlePageNt.articleNtHrf+'"  \n' +
                    '                               title="下一篇：' + articleContentJson.articlePageNt.articleNtTitle + '">' + articleContentJson.articlePageNt.articleNtTitle +
                    '<i class="fa fa-chevron-right ml-1"></i>\n' +
                    '                            </a>\n' +
                    '                            <a class="d-md-none" href="'+content_url+'/index.html?model=articleInfo&id=' + articleContentJson.articlePageNt.articleNtHrf + '">\n' +
                    '                                下一篇<i class="fa fa-chevron-right ml-1"></i>\n' +
                    '                            </a>\n' +
                    '                        </li>\n' +
                    '                    </ul>\n' +
                    '                </nav>\n' +
                    '            </div>\n' +
                    '        </div>\n' +
                    '    </div>';

                $(".home-content").html(articleContentHtml);
                $("meta[name='description']").attr('content', articleContentJson.articleDescription);

                $(".articleContent").addClass("markdown-body editormd-html-preview").append(articleContentJson.articleContent);

            }

        }
    });

    //获取和设置评论
    $(".commentContentInput").val(id);
    showComment(id);
}

function showComment(id){
    //文章评论
    $.ajax({
        type: 'GET',
        url: '/blog/blogViewController/getCommentById',
        dataType: "json",
        data: "articleId="+id,
        async: false,
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var datas = result.data;
                $(".comment-list").html("");
                $(".comment-list").addCommentList({data:datas,add:""});

                showHide();
            }
        }
    });
}

//显示或隐藏评论
function showHide(){

    //隐藏文章评论
    $(".commentcontent").hide();
    $(".commentbox2").show();
    $(".reply-btn").hide();
    $(".reply p span").hide();

    var cookieJWT = getLocalStorage('malongxiaozhan-user-jwt', expUser);
    var cookieUserName = getLocalStorage('malongxiaozhan-user-userName', expUser);
    if (cookieJWT !== null && cookieUserName !== "null" && cookieUserName !== 'undefined' && cookieUserName !== undefined
        && cookieUserName !== null && cookieUserName !== 'undefined' && cookieUserName !== undefined) {

        //显示评论区
        $(".commentcontent").show();
        $(".commentbox2").hide();
        $(".reply-btn").show();
        $(".reply p span").show();
    }
}

//分类列表
function sortHomeContent(pageCurrent, id, modelType) {
    var sorHomeHtml = '';
    $.ajax({
        type: 'GET',
        url: '/blog/blogArticleView/getSortList',
        dataType: "json",
        data: "id="+id,
        async: false,
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var sortHomeJson = result.data[0];
                sorHomeHtml += '<div class=" col-12 px-3 mb-2 mb-md-3 bg-light   ">\n' +
                    '        <div class=" bg-light px-3 pt-3 pb-1 ">\n' +
                    '            <p class="text-right mb-0 float-end f-15" >共<span class="mx-2 text-info">' + sortHomeJson.contentNu + '</span>篇</p>\n' +
                    '            <h1 class="f-17 border-bottom border-5 border-info"><strong class="  ">' + sortHomeJson.title + '</strong></h1>\n' +
                    '            <p class="f-16">' + sortHomeJson.content + '</p>\n' +
                    '        </div>\n' +
                    '    </div>\n' +
                    '    <div class=" col-12 m-0 p-0  container  ">';


                $("meta[name='description']").attr('content', sortHomeJson.content);

            }

        }
    });

    var param = {"pageNo":pageCurrent,"pageSize":10,"sortId":id};
    $.ajax({
        type: 'POST',
        url: '/blog/blogArticleView/homeContent', //要请求的url地址
        data: JSON.stringify(param), //传入的数据 转换为json对象
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var homeContenJsons = {
                    "pageTotal": result.data.total,
                    "pageCurrent": result.data.current,
                    "data": result.data.records,
                    "pages": result.data.pages
                };
                var commonHomes = commonHome(homeContenJsons);
                sorHomeHtml += commonHomes.html;

                //添加内容
                $(".home-content").html(sorHomeHtml);
                //添加内容分页
                $(".home-content-page").html(homePage(homeContenJsons, modelType, id));

                homeImgWh(commonHomes.imgId);
            }

        }
    });
}

//标签列表
function tagHomeContent(pageCurrent, id, modelType) {
    var sorHomeHtml = '';
    $.ajax({
        type: 'GET',
        url: '/blog/blogArticleView/getTagList',
        dataType: "json",
        data: "id="+id,
        async: false,
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var tagHomeJson = result.data[0];
                sorHomeHtml += '<div class=" col-12 px-3 mb-2 mb-md-3 bg-light   ">\n' +
                    '        <div class=" bg-light px-3 pt-3 pb-1 ">\n' +
                    '            <p class="text-right mb-0 float-end f-15" >共<span class="mx-2 text-info">' + tagHomeJson.contentNu + '</span>篇</p>\n' +
                    '            <h1 class="f-17 border-bottom border-5 border-info"><strong class="  ">' + tagHomeJson.title + '</strong></h1>\n' +
                    '            <p class="f-16">' + tagHomeJson.content + '</p>\n' +
                    '        </div>\n' +
                    '    </div>\n' +
                    '    <div class=" col-12 m-0 p-0  container  ">';

                $("meta[name='description']").attr('content', tagHomeJson.content);
            }

        }
    });

    var param = {"pageNo":pageCurrent,"pageSize":10,"tagId":id};
    $.ajax({
        type: 'POST',
        url: '/blog/blogArticleView/homeContent', //要请求的url地址
        data: JSON.stringify(param), //传入的数据 转换为json对象
        dataType: "json",
        headers: {
            "Content-Type": 'application/json'
        },//设置请求头
        success: function (result) {
            if(result.code === '200'){
                var homeContenJsons = {
                    "pageTotal": result.data.total,
                    "pageCurrent": result.data.current,
                    "data": result.data.records,
                    "pages": result.data.pages
                };
                var commonHomeValue = commonHome(homeContenJsons);
                sorHomeHtml += commonHomeValue.html;

                //添加内容
                $(".home-content").html(sorHomeHtml);
                //添加内容分页
                $(".home-content-page").html(homePage(homeContenJsons, modelType, id));

                homeImgWh(commonHomeValue.imgId);
            }

        }
    });
}
